//---------------------------------------------
//            Tasharen Network
// Copyright © 2012-2013 Tasharen Entertainment
//---------------------------------------------
using System.IO;

namespace TNet
{
    // socket内部事件枚举定义(1-1000)
    public enum Packet : ushort
    {
        Error = 1, // 返回错误信息
        Connect = 2, // 连接成功
        Disconnect = 3, // 连接中断
    }

    // 错误消息
    public class ErrorMsg : MsgBase
    {
        public ErrorMsg() : base((ushort)Packet.Error)
        {

        }

        public ServerType serverType; // 服务器类型
        public string Error; // 错误消息

        // 写入到二进制当中
        public override void WriterBinary(BinaryWriter binary)
        {
            binary.Write((byte)serverType);
            binary.Write(Error);
        }

        // 从二进制当中读取数据
        public override void ReadByBinary(BinaryReader binary)
        {
            serverType = (ServerType)binary.ReadByte();
            Error = binary.ReadString();
        }
    }

    // 连接结束
    public class ConnectMsg : MsgBase
    {
        public ConnectMsg() : base((ushort)Packet.Connect)
        {

        }

        public ServerType serverType; // 服务器类型
        public bool bSucc; // 是否成功
        public string ip; // 地址
        public ushort prot;

        // 写入到二进制当中
        public override void WriterBinary(BinaryWriter binary)
        {
            binary.Write((byte)serverType);
            binary.Write(bSucc);
            binary.Write(ip);
            binary.Write(prot);
        }

        // 从二进制当中读取数据
        public override void ReadByBinary(BinaryReader binary)
        {
            serverType = (ServerType)binary.ReadByte();
            bSucc = binary.ReadBoolean();
            ip = binary.ReadString();
            prot = binary.ReadUInt16();
        }
    }

    // 连接中断
    public class DisconnectMsg : MsgBase
    {
        public DisconnectMsg() : base((ushort)Packet.Disconnect)
        {

        }

        public ServerType serverType; // 服务器类型

        // 写入到二进制当中
        public override void WriterBinary(BinaryWriter binary)
        {
            binary.Write((byte)serverType);
        }

        // 从二进制当中读取数据
        public override void ReadByBinary(BinaryReader binary)
        {
            serverType = (ServerType)binary.ReadByte();
        }
    }
}
